package com.open.cloud.rbac.config;


import com.inspur.micro.core.config.InsCoreConfig;
import com.inspur.micro.core.security.JwtFilter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author wangzengzhou
 */
@Configuration
@EnableConfigurationProperties
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private InsCoreConfig insCoreConfig;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JwtFilter(insCoreConfig.getSecurity()))
                .addPathPatterns("/**")
                .excludePathPatterns(Arrays.asList("/actuator/**", "/doc.html", "/webjars/**", "/v2/api-docs/**", "/v3/api-docs/**", "/swagger-resources/**", "/favicon.ico"));

//        // 接口幂等性拦截器

//        //文件格式校验拦截器
//        registry.addInterceptor(fileHeaderCheckInterceptor());
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        //配置拦截器访问静态资源
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
//
//    /**
//     * 时间日期格式转化
//     *
//     * @param registry
//     */
//    @Override
//    public void addFormatters(FormatterRegistry registry) {
//        DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
//        registrar.setUseIsoFormat(true);
//        registrar.registerFormatters(registry);
//    }


}
